package com.example.sls.service.impl.teacher.proSet;

import com.example.sls.mapper.teacher.proSet.ProSetMapper;
import com.example.sls.pojo.teacher.proSet.ProSet;
import com.example.sls.service.teacher.proSet.ProSetService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ProSetServiceImpl implements ProSetService {

    @Autowired
    private ProSetMapper proSetMapper;

    @Override
    public ProSet getProSetBySetId(Integer setId) {
        return proSetMapper.getProSetBySetId(setId);
    }

    @Override
    public List<ProSet> getProSetByTId(Integer TId) {
        return proSetMapper.getProSetByTId(TId);
    }

    @Override
    public PageInfo<ProSet> getPageInfoByTId(Integer TId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<ProSet> proSets = proSetMapper.getProSetByTId(TId);
        return new PageInfo<ProSet>(proSets);
    }

    @Override
    public List<ProSet> getProSetInfo() {
        return proSetMapper.getProSetInfo();
    }

    @Override
    public Boolean addProSet(Integer selId, Integer createdBy) {
        boolean flag = false;
        Integer id = proSetMapper.getMaxId() + 1;
        Date createDate = new Date();
        ProSet proSet = new ProSet(id, selId, createdBy, createDate);
        if(proSetMapper.addProSet(proSet) > 0){
            flag = true;
        }
        return flag;
    }

    @Override
    public Integer getMaxId() {
        return proSetMapper.getMaxId();
    }

    @Override
    public Integer getCount() {
        return proSetMapper.getCount();
    }
}
